//
//  LGOrderUserInfoView.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/3/14.
//  就诊人信息

#import "LGOrderUserInfoView.h"

@interface LGOrderUserInfoView()

/**   */
@property (nonatomic , strong)UIButton *titleBtn;
/**   */
@property (nonatomic , strong)UILabel *userLabel;
/**   */
@property (nonatomic , strong)UIView *userView;
/**   */
@property (nonatomic , strong)UIButton *patientTitle;
/**   */
@property (nonatomic , strong)UILabel *patientLabel;
/**   */
@property (nonatomic , strong)UIButton *descripTitle;
/**   */
@property (nonatomic , strong)UILabel *descripLabel;

@end

@implementation LGOrderUserInfoView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.titleBtn];
    }
    return self;
}


-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    
    NSString *type = LGNSString(dataDic[@"appointment_type"]);
    NSString *userName = [NSString stringWithFormat:@"%@  %@ %@岁",dataDic[@"patient"][@"realname"],dataDic[@"patient"][@"gender"],dataDic[@"patient"][@"age"]];
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc]initWithString:userName];
    [attStr addAttributes:@{NSFontAttributeName:LGFont(16),NSForegroundColorAttributeName:[UIColor colorWithString:@"#333333"]} range:NSMakeRange(0, [dataDic[@"patient"][@"realname"] length])];
    if([type isEqualToString:@"1"]){
        [self addSubview:self.userLabel];
        self.userLabel.attributedText = attStr;
        [self.userLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(viewPix(49));
            make.left.equalTo(self).offset(viewPix(16));
            make.right.bottom.equalTo(self).offset(-viewPix(16));
            make.height.equalTo(@(viewPix(23)));
        }];
    }else{
        [self addSubview:self.userView];
        [self.userView addSubview:self.patientTitle];
        [self.userView addSubview:self.patientLabel];
        [self.userView addSubview:self.descripTitle];
        [self.userView addSubview:self.descripLabel];
        self.patientLabel.attributedText = attStr;
        //运动评估不显示描述
        self.descripTitle.hidden = [type isEqualToString:@"5"]?YES:NO;
        self.descripLabel.hidden = [type isEqualToString:@"5"]?YES:NO;
        CGFloat top = [type isEqualToString:@"5"]?viewPix(70):viewPix(104);
        self.descripLabel.text = LGNSString(dataDic[@"patient"][@"situation"]);
        [self.descripLabel lineSpacing:5];
        [self.userView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(viewPix(46));
            make.left.equalTo(self).offset(viewPix(12));
            make.right.equalTo(self).offset(-viewPix(12));
            make.bottom.equalTo(self).offset(-viewPix(16));
        }];
        [self.descripLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.userView).offset(top);
            make.left.equalTo(self.userView).offset(viewPix(28));
            make.right.equalTo(self.userView).offset(-viewPix(20));
            make.bottom.equalTo(self.userView).offset(-viewPix(8));
        }];
    }
}

-(void)setPatientInfo:(NSDictionary *)patientInfo{
    _patientInfo = patientInfo;
    [self addSubview:self.userLabel];
    NSString *userName = [NSString stringWithFormat:@"%@  %@ %@岁",patientInfo[@"realname"],patientInfo[@"gender"],patientInfo[@"age"]];
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc]initWithString:userName];
    [attStr addAttributes:@{NSFontAttributeName:LGFont(16),NSForegroundColorAttributeName:[UIColor colorWithString:@"#333333"]} range:NSMakeRange(0, [LGNSString(patientInfo[@"realname"]) length])];
    self.userLabel.attributedText = attStr;
    [self.userLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(viewPix(49));
        make.left.equalTo(self).offset(viewPix(16));
        make.right.bottom.equalTo(self).offset(-viewPix(16));
        make.height.equalTo(@(viewPix(23)));
    }];
}


#pragma mark
#pragma mark ====> 创建控件
-(UIButton *)titleBtn{
    if(!_titleBtn){
        _titleBtn = [UIButton buttonWithTitle:@"用户信息" titleFont:LGFontWeight(16, UIFontWeightMedium) textColor:@"#333333" imageName:@"订单详情-就诊人信息"];
        _titleBtn.frame = CGRectMake(viewPix(16), viewPix(12), viewPix(150), viewPix(22));
        _titleBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _titleBtn.titleEdgeInsets = UIEdgeInsetsMake(0, viewPix(4), 0, 0);
    }
    return _titleBtn;
}

-(UILabel *)userLabel{
    if(!_userLabel){
        _userLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(15) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _userLabel;
}

-(UIView *)userView{
    if(!_userView){
        _userView = [[UIView alloc] init];
        _userView.backgroundColor = [UIColor colorWithString:@"#F7F9FB"];
        _userView.cornerRidus = 5;
    }
    return _userView;
}

-(UIButton *)patientTitle{
    if(!_patientTitle){
        _patientTitle = [UIButton buttonWithTitle:@"咨询者" titleFont:LGFont(15) textColor:@"#666666" imageName:@"订单详情-就诊人"];
        _patientTitle.frame = CGRectMake(viewPix(8), viewPix(8), viewPix(100), viewPix(21));
        _patientTitle.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _patientTitle.titleEdgeInsets = UIEdgeInsetsMake(0, viewPix(6), 0, 0);
    }
    return _patientTitle;
}

-(UILabel *)patientLabel{
    if(!_patientLabel){
        _patientLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(15) textAlignment:NSTextAlignmentLeft lines:1];
        _patientLabel.frame = CGRectMake(viewPix(28), viewPix(37), Screen_W-viewPix(105), viewPix(22));
    }
    return _patientLabel;
}

-(UIButton *)descripTitle{
    if(!_descripTitle){
        _descripTitle = [UIButton buttonWithTitle:@"病情描述" titleFont:LGFont(15) textColor:@"#666666" imageName:@"订单详情-病情描述"];
        _descripTitle.frame = CGRectMake(viewPix(8), viewPix(75), viewPix(100), viewPix(21));
        _descripTitle.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _descripTitle.titleEdgeInsets = UIEdgeInsetsMake(0, viewPix(6), 0, 0);
    }
    return _descripTitle;
}

-(UILabel *)descripLabel{
    if(!_descripLabel){
        _descripLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(15) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _descripLabel;
}

@end
